<?php

/**
 * This is the model class for table "mst_client_persons".
 *
 * The followings are the available columns in table 'mst_client_persons':
 * @property integer $id
 * @property integer $mst_client_id
 * @property string $title
 * @property string $full_name
 * @property string $birth_place
 * @property string $birth_date
 * @property string $gender
 * @property string $address
 * @property string $city
 * @property string $province
 * @property string $zip
 * @property string $phone
 * @property string $mobile
 * @property integer $createdby
 * @property string $createdtime
 * @property integer $updatedby
 * @property string $updatedtime
 */
class MstClientPersons extends CActiveRecord
{
	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'mst_client_persons';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('birth_place, gender, address, city, province, createdby', 'required'),
			array('mst_client_id, createdby, updatedby', 'numerical', 'integerOnly'=>true),
			array('title', 'length', 'max'=>5),
			array('full_name', 'length', 'max'=>50),
			array('birth_place, city, province', 'length', 'max'=>100),
			array('gender, zip', 'length', 'max'=>10),
			array('phone, mobile', 'length', 'max'=>25),
			array('birth_date', 'safe'),
			// The following rule is used by search().
			// @todo Please remove those attributes that should not be searched.
			array('id, mst_client_id, title, full_name, birth_place, birth_date, gender, address, city, province, zip, phone, mobile, createdby, createdtime, updatedby, updatedtime', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'mst_client_id' => 'Mst Client',
			'title' => 'Title',
			'full_name' => 'Full Name',
			'birth_place' => 'Birth Place',
			'birth_date' => 'Birth Date',
			'gender' => 'Gender',
			'address' => 'Address',
			'city' => 'City',
			'province' => 'Province',
			'zip' => 'Zip',
			'phone' => 'Phone',
			'mobile' => 'Mobile',
			'createdby' => 'Createdby',
			'createdtime' => 'Createdtime',
			'updatedby' => 'Updatedby',
			'updatedtime' => 'Updatedtime',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 *
	 * Typical usecase:
	 * - Initialize the model fields with values from filter form.
	 * - Execute this method to get CActiveDataProvider instance which will filter
	 * models according to data in model fields.
	 * - Pass data provider to CGridView, CListView or any similar widget.
	 *
	 * @return CActiveDataProvider the data provider that can return the models
	 * based on the search/filter conditions.
	 */
	public function search($id)
	{
		// @todo Please modify the following code to remove attributes that should not be searched.

		$criteria=new CDbCriteria;
		$criteria->condition = 'mst_client_id='.$id;

		$criteria->compare('id',$this->id);
		$criteria->compare('mst_client_id',$this->mst_client_id);
		$criteria->compare('title',$this->title,true);
		$criteria->compare('full_name',$this->full_name,true);
		$criteria->compare('birth_place',$this->birth_place,true);
		$criteria->compare('birth_date',$this->birth_date,true);
		$criteria->compare('gender',$this->gender,true);
		$criteria->compare('address',$this->address,true);
		$criteria->compare('city',$this->city,true);
		$criteria->compare('province',$this->province,true);
		$criteria->compare('zip',$this->zip,true);
		$criteria->compare('phone',$this->phone,true);
		$criteria->compare('mobile',$this->mobile,true);
		$criteria->compare('createdby',$this->createdby);
		$criteria->compare('createdtime',$this->createdtime,true);
		$criteria->compare('updatedby',$this->updatedby);
		$criteria->compare('updatedtime',$this->updatedtime,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}

	/**
	 * Returns the static model of the specified AR class.
	 * Please note that you should have this exact method in all your CActiveRecord descendants!
	 * @param string $className active record class name.
	 * @return MstClientPersons the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}
}
